new Vue({
    el: '#app',
    data() {
        return {
            id:'',
            formData: {},
        }
    },
    beforeCreate() {
        function setRem() {
            const designWidth = 750; // 设计稿宽度（rpx）
            const maxWidth = 540; // 可选：限制最大宽度（如手机端常见值）
            const screenWidth = Math.min(window.innerWidth, maxWidth);
            const scale = screenWidth / designWidth;
            document.documentElement.style.fontSize = scale + 'px';
        }
        setRem();//1rem = 0.5px 对标小程序在 375px 宽的屏幕上，1rpx = 0.5px（因为 750rpx / 375px = 2）
    },
    mounted() {
        let URL = window.location.href;
        this.id = getQueryObject(URL, 'id');
        this.init();
    },
    methods: {
        async init(callback) {
            await Promise.allSettled([
                this.getList(),
            ]);
            callback ? callback() : null;
        },
        async getList() {
            try {
                const data = await generalApi.generalQueryBySQLSerialNumberWithClient({
                    SQLSerialNumber: 'x_farm_operation_record',
                    Condition: utf8ToBase64('%%'),
                    ExtensionCondition: utf8ToBase64(`AND farm_operation_record.Farm_Operation_SerialNumber='${this.id}' AND farm_operation_record.Open_ID='${getCookie('openId')}' AND farm_operation_record.Creater_SerialNumber='${getCookie('user')}'`),
                })
                this.formData = data[0] || {};
            } catch (error) {
                console.error(error);
            }
        },
        async handleRemove() {
            try {
                const data = await generalApi.generalQueryByTableNameWithOriginal({
                    Data: 'farm_operation_record',
                    Condition: `Farm_Operation_SerialNumber='${this.id}'`
                });
                if (data.length == 1) {
                    data[0].Row_Status = '1';
                    let lJSONObject_Modify = new Object();
                    lJSONObject_Modify['farm_operation_record'] = data;
                    let lJSONObject_DataSet = { Modify: lJSONObject_Modify, Add: {} };
                    let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                    lJSONObject_DataSet['Add']['base_operation_log'] = [{
                        Operation_Type: '0',
                        Operation_Path: getRelativePath(),
                        Operation_Description: '删除数据',
                        Operation_Main,
                        Operation_Interface: 'generalSaveByRequestBody',
                        Operation_IP: getIpAddress()
                    }];
                    const res = await generalApi.generalSaveByRequestBody({ Data: lJSONObject_DataSet });
                    if (res.Status == 'success') {
                        this.$showToast({ title: '删除成功' });
                        window.location.href = '../../pages/index/farm_operation_record.html';
                    } else {
                        this.$showToast({ title: '删除失败，请重试！' });
                    }
                }
            } catch (error) {
                console.error(error);
                this.$showToast({ title: '系统错误，请联系开发者' });
            }
        }

    },
})
